package edu.ynu.se.xiecheng.achitectureclass.controller;

import edu.ynu.se.xiecheng.achitectureclass.dto.TemperatureDataDTO;
import edu.ynu.se.xiecheng.achitectureclass.service.TemperatureDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Api(tags = "土壤温度数据接口")
@RestController
@RequestMapping("/api/temperature-data")
@RequiredArgsConstructor
public class TemperatureDataController {
    private final TemperatureDataService temperatureDataService;

    @ApiOperation("获取指定时间范围内的温度数据")
    @GetMapping
    public ResponseEntity<List<TemperatureDataDTO>> getTemperatureData(
            @RequestParam Long start,
            @RequestParam Long end) {
        Date startDate = new Date(start);
        Date endDate = new Date(end);
        return ResponseEntity.ok(temperatureDataService.getTemperatureData(startDate, endDate));
    }

    @ApiOperation("手动触发温度数据采集")
    @PostMapping("/collect")
    public ResponseEntity<Void> collectTemperatureData() {
        temperatureDataService.collectTemperatureData();
        return ResponseEntity.ok().build();
    }
}